<template>
  <div class="optimal_pro">
    <div class="recommend_pro">
      <span class="bi bi-cursor-fill"></span>
      <span>优品推荐</span>
    </div>
    <div>
      <van-swipe @change="onChange" class="optimal_list">
        <van-swipe-item class="op_list">
          <div class="product_list" v-for="item in swipe" :key="item.id">
            <div class="pro_img">
              <img :src="item.image" alt="" />
            </div>
            <div class="pro_txt">
              <span>{{ item.store_name }}</span>
            </div>
            <div class="pro_price">
              <span>￥{{ item.price }}</span>
            </div>
          </div>
        </van-swipe-item>
        <van-swipe-item class="op_list">
          <div class="product_list" v-for="item in list" :key="item.id">
            <div class="pro_img">
              <img :src="item.image" alt="" />
            </div>
            <div class="pro_txt">
              <span>{{ item.store_name }}</span>
            </div>
            <div class="pro_price">
              <span>￥{{ item.price }}</span>
            </div>
          </div>
        </van-swipe-item>
        <van-swipe-item class="op_list">
          <div class="product_list" v-for="item in itemlist" :key="item.id">
            <div class="pro_img">
              <img :src="item.image" alt="" />
            </div>
            <div class="pro_txt">
              <span>{{ item.store_name }}</span>
            </div>
            <div class="pro_price">
              <span>￥{{ item.price }}</span>
            </div>
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Swipe, SwipeItem } from "vant";
import { Toast } from "vant";

import { mapState } from "vuex";

Vue.use(Swipe);
Vue.use(SwipeItem);

export default {
  data() {
    return {
      swipe: [],
      list: [],
      itemlist: [],
      timer : null,
    }
  },
  computed: {
    ...mapState(["commod"]),
  },
  methods: {
    onChange(index) {
      Toast("当前 Swipe 索引：" + index);
    },
    init() {
      let array = this.$store.state.commod.commodList[0].goodlist;
      let arr1 = array.slice(0, 6);
      let arr2 = array.slice(6, 12);
      let arr3 = array.slice(12, 18);
      this.swipe = arr1;
      this.list = arr2;
      this.itemlist = arr3;
    }
  },
  // created() {
  //   this.init();
  // },
  mounted(){
    this.timer = setInterval( ()=> {
      this.init();
    },100);
  }
};
</script>

<style lang="less">
.recommend_pro {
  height: 40px;
  line-height: 40px;
  color: #f00;
  font-size: 16px;
  padding-left: 20px;
  background: #fff;
  span {
    padding-left: 5px;
  }
}
.optimal_list {
  height: 350px;
  margin-bottom: 10px;
  background: #fff;
  // .op_list{
  // &:after {
  //   content: url("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F4f1b730df97436c1bf843f59a416411d9fed7b7b9ba90-98pV5p_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644290338&t=edb94fefa14048a27028e8c42cdd71e1");
  //   display: block;
  //   position: absolute;
  //   z-index: 2;
  //   top: 0;
  //   left: 0;
  //   width: 100%;
  //   height: 100%;
  //   background-color: #fff;
  // }
  // }
}
.product_list {
  width: 120px;
  height: 150px;
  float: left;
  margin-left: 4.1px;
  margin-top: 10px;
  border-radius: 8px;
  .pro_img {
    width: 120px;
    height: 100px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    img {
      width: 100%;
      height: 100%;
      display: block;
      border-top-left-radius: 8px;
      border-top-right-radius: 8px;
      // &:after {
      //   content: url("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F4f1b730df97436c1bf843f59a416411d9fed7b7b9ba90-98pV5p_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644290338&t=edb94fefa14048a27028e8c42cdd71e1");
      //   display: block;
      //   position: absolute;
      //   z-index: 2;
      //   top: 0;
      //   left: 0;
      //   width: 100%;
      //   height: 100%;
      //   background-color: #fff;
      // }
    }
  }
  .pro_txt {
    font-size: 18px;
    height: 30px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding-left: 5px;
  }
  .pro_price {
    font-size: 16px;
    color: #9334a2;
    padding-left: 5px;
  }
}
</style>